<script>
import {managementSetDel, managementSetEdit, setAdd, setList} from "@/api/evaluationManagement/http";
import log from "@/views/monitor/job/log.vue";
// import {classDelete} from "@/api/class/http";

export default {
  data() {
    return {
      newOptions:'',
      titlePro: '',
      id: this.$route.query.id,
      dialogVisible: false,
      tableData: [],
      multipleSelection: [],
      // 计数器
      num: 0,
      numMax: 0,
      // 输入框
      textarea: '',
      promptContent: '',
      newArray: {
        assessmentId: this.$route.query.id,
        analysis: '',
        lowest: '',
        highest: ''
      },
      addFormData: {
        assessmentId: this.$route.query.id,
        analysis: "",
        lowest: '',
        highest: ''
      },
      addData: {
        analysis: '',
        lowest: '',
        highest: ''
      }

    }
  },
  created() {
    this.getList()
    // this.getAdd()
  },
  methods: {
//     删除
    deleteDom(row){
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        managementSetDel([row.id]).then((res) => {
          if (res.code === 200) {
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
            this.getList()
            // evaluation().then(res => {
            //   console.log(res)
            //   this.tableData = res.rows
            // })
          }

        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
//     点击编辑
    edit(row) {
      // this.addFormData.id = row.id
      this.dialogVisible = true
      this.titlePro = '编辑'
      this.addData={
        id:row.id,
        analysis:row.analysis,
        lowest: row.lowest,
        highest: row.highest
      }
    },
//     点击添加
    add() {
      // delete this.addFormData.id
      this.dialogVisible = true
      this.titlePro = '添加'
      this.addData={
        assessmentId:this.id,
        analysis:'',
        lowest:'',
        highest:''
      }
    },
//     方法
    getList() {
      setList(this.id).then(res => {
        console.log(res)
        this.tableData = res.rows
      })
    },
    // 添加方法
    getAdd() {
      setAdd({
        assessmentId: this.id,
        analysis: null,
        lowest: 0,
        highest: 100
      }).then(res => {
        console.log(res)
        this.tableData = res.rows
      })
    },
    //确认按钮
    addEdit() {
      this.dialogVisible = false
      console.log(this.addFormData.id)
      if (this.titlePro==='编辑') {

        managementSetEdit(this.addData).then(res => {
          console.log(res)
          this.getList()
        })
      } else {
        setAdd(this.addData).then(res => {
          console.log(res)
          console.log(this.tableData)
          // this.tableData.lowest = this.num + '~' + this.numMax
          // setList(this.id).then(res=>{
          //   console.log(res)
          //   this.tableData=res.rows
          // })
          // this.getAdd()
          // console.log(this.tableData.lowest)
          this.$message({
            type: 'success',
            message: '添加成功!'
          })
          this.getList()
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '添加失败'
          });
        })
      }


    },
    // 计数器
    handleChange(value) {
      console.log(value);
    },
    // 编辑弹框
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {
        });
    },
    // 管理表格
    toggleSelection(rows) {
      if (rows) {
        rows.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    }
  }

}
</script>

<template>
  <div>
    <div class="container">
      <div class="evaluation">
        <div class="add">
          <el-button type="primary" size="small" @click="add" style="color: white;font-size: 0.8rem ;padding: 10px 20px">
            添加
          </el-button>
        </div>
        <!--        管理表格-->
        <div class="mange">
          <template>
            <el-table
              ref="multipleTable"
              :data="tableData"
              tooltip-effect="dark"
              style="width: 98%;text-align: center; margin-left: 30px"
              @selection-change="handleSelectionChange" border >
              <el-table-column
                prop="analysis"
                label="提示内容"
                v-model="promptContent"
                class="center">
              </el-table-column>
              <el-table-column
                label="分数范围"
                width="300">
                <template #default="{row}">
                  {{row.lowest}}~{{row.highest}}
                </template>
              </el-table-column>
              <el-table-column
                label="操作"
                width="300">
                <template slot-scope="scope">
                  <el-button type="text" size="small" @click="edit(scope.row)">编辑</el-button>
                  <el-button type="text" @click="deleteDom(scope.row)" size="small">删除</el-button>
                </template>
              </el-table-column>
            </el-table>

          </template>
        </div>

        <!--      添加弹窗-->
        <el-dialog :visible.sync="dialogVisible" class="redact" width="50%" :title="titlePro"
                   :before-close="handleClose">
          <el-form :model="addData">
            <!--          <div class="redact">-->
            <!--            添加-->
            <!--          </div>-->
            <div class="setting">
              <div class="radius">
                分数范围<br>
                <template>
                  <el-input-number v-model="addData.lowest" controls-position="right" @change="handleChange"
                                   :min="0"></el-input-number>
                </template>
                <span class="approximate">~</span>
                <template>
                  <el-input-number v-model="addData.highest" controls-position="right" @change="handleChange"
                                   :min="0"></el-input-number>
                </template>
              </div>
              <div class="Message">
                内容信息<br>
                <!--              输入框-->
                <el-input
                  type="textarea"
                  placeholder="请输入内容"
                  v-model="addData.analysis"
                  maxlength="500"
                  show-word-limit
                  resize="none"
                  rows="15"
                >
                </el-input>
              </div>
            </div>
          </el-form>
          <!--          </div>-->
          <span slot="footer" class="dialog-footer">
    <el-button class="cancel" @click="dialogVisible = false">取 消</el-button>
    <el-button class="cancel" type="primary" @click="addEdit">保 存</el-button>
</span>

        </el-dialog>

      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.container {
  width: 100%;
  height: calc(100vh - 84px);
  background-color: #F2F3F4;
  padding: 10px 20px;

  .evaluation {
    width: 100%;
    height: 100%;
    background-color: white;
    padding: 30px 20px;
  }
}

.redact {
  width: 100%;
  //background-color: #1892FF;
  padding: 20px;
  color: white;
  margin-top: -30px;
}

.cancel {
  height: 40px;
}

.setting {
  width: 100%;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;

  .radius {
    margin: 20px;
    width: 80%;
    font-size: 1rem;
    line-height: 50px;

    .approximate {
      font-size: 28px;
      font-weight: 500;
      margin: 0 20px;
    }
  }

  .Message {
    width: 80%;
    font-size: 1rem;
    line-height: 50px;
  }
}

.mange {
  margin-top: 50px;
  margin-left: -30px;
}
::v-deep .dialog-footer{
  display: flex;
  justify-content: center;
  margin-top: 20px;
}

::v-deep .el-dialog__header {
  background-color: #1892ff;
}

::v-deep .el-dialog__title {
  color: white;
}

::v-deep .el-dialog {
  border-radius: 8px;
  overflow: hidden;
}

::v-deep .container .evaluation[data-v-1f5bf6c4] [data-v-1f5bf6c4] .el-button--medium {
  padding: 0 20px;
}

::v-deep .el-dialog__body {
  padding: 0;
}

::v-deep .el-dialog__headerbtn .el-dialog__close {
  color: white;
}

::v-deep .el-button--medium {
  padding: 10px 20px;
}

::v-deep .el-table th.el-table__cell > .cell {
  text-align: center;
}

::v-deep .el-table--border .el-table__cell:first-child .cell {
  text-align: center;
}

::v-deep .el-table .cell.el-tooltip {
  text-align: center;
}

::v-deep .el-table .cell {
  text-align: center;
}
::v-deep .el-table .el-table__header-wrapper th {
  background-color: #f8f8f8;
}
</style>
